import { computed } from 'vue'
import { useStore, mapGetters } from 'vuex'
import { keys } from 'lodash'

/**
 * 多个getter获取方法
 * @param modelName 模块的名称
 * @param modelGetterNames 需要获取的getters名称数组
 * @returns 返回的都是vue的ref对象取值必须.value才能拿到
 */
export default function (modelName: string, modelGetterNames: string[]) {
  const store = useStore()
  const getters = mapGetters(modelName, modelGetterNames)
  // 对数据进行转换
  return keys(getters).reduce(
    (obj: any, key: string | number) =>
      Object.assign(obj, { [key]: computed(getters[key].bind({ $store: store })) }),
    {}
  )
}
